<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-card>
        <el-form-item label="工程名称" prop="name">
          <el-input
            v-model="queryParams.name"
            placeholder="请输入工程名称"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="工程代码" prop="code">
          <el-input
            v-model="queryParams.code"
            placeholder="请输入工程代码"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="启动日期" prop="startTime">
          <el-date-picker clearable size="small" style="width:100%;" v-model="queryParams.startTime" type="date" value-format="yyyy-MM-dd" placeholder="选择启动日期"></el-date-picker>
        </el-form-item>
        <!-- <el-form-item label="竣工日期" prop="endTime">
          <el-date-picker clearable size="small" style="width:100%;" v-model="queryParams.endTime" type="date" value-format="yyyy-MM-dd" placeholder="选择竣工日期"></el-date-picker>
        </el-form-item>
        <el-form-item label="工程金额" prop="costConstruction">
          <el-input
            v-model="queryParams.costConstruction"
            placeholder="请输入工程金额"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item> -->
        <el-form-item label="工程状态 " prop="status">
          <el-select v-model="queryParams.status" placeholder="请选择工程状态 " clearable size="small">
            <el-option
              v-for="(dict,index) in dict.type.sys_engineer_status"
              :key="'b'+index"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-card>
    </el-form>

    <el-card style="margin-top:10px;">
      <el-table v-loading="loading" :data="engineerList" border>
        <el-table-column label="工程名称" align="center" prop="name" />
        <el-table-column label="工程代码" align="center" prop="code" />
        <el-table-column label="所属项目" align="center" prop="projectName" />
        <el-table-column label="启动日期" align="center" prop="startTime" />
        <el-table-column label="竣工日期" align="center" prop="endTime" />
        <el-table-column label="负责人" align="center" prop="chargerName" />
        <el-table-column label="负责部门" align="center" prop="deptName" />
        <el-table-column label="工程金额(万元)" align="center" prop="costConstruction">
          <template slot-scope="scope">
            <span style="color:blue;">{{ scope.row.costConstruction | moneyFormat }}</span>
          </template>
        </el-table-column>
        <el-table-column label="施工单位" align="center" prop="ownerDept" />
        <el-table-column label="监理单位" align="center" prop="supervisor" />
        <el-table-column label="施工联系人" align="center" prop="contactPerson" />
        <el-table-column label="联系方式" align="center" prop="contactPhone" />
        <el-table-column label="工程状态" align="center" prop="status">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.sys_engineer_status" v-if="scope.row.status==1" style="color:red;" :value="scope.row.status"/>
            <dict-tag :options="dict.type.sys_engineer_status" v-if="scope.row.status==2" style="color:blue;" :value="scope.row.status"/>
            <dict-tag :options="dict.type.sys_engineer_status" v-if="scope.row.status==3" style="color:green;" :value="scope.row.status"/>
            <dict-tag :options="dict.type.sys_engineer_status" v-if="scope.row.status==4" style="color:gray;" :value="scope.row.status"/>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-dropdown :hide-on-click="false">
              <span class="el-dropdown-link" style="color:blue;">
                更多操作<i class="el-icon-arrow-down el-icon--right"></i>
              </span>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item @click.native="handleView(scope.row)"><i class="el-icon-document"></i>工程详情</el-dropdown-item>
                <el-dropdown-item style="color:blue;" @click.native="handleUpdate(scope.row)"><i class="el-icon-edit-outline"></i>工程修改</el-dropdown-item>
                <el-dropdown-item style="color:green;" v-if="scope.row.status==1" @click.native="handleStart(scope.row)"><i class="el-icon-s-promotion"></i>工程启动</el-dropdown-item>
                <el-dropdown-item style="color:orange;" v-if="scope.row.status==2" @click.native="handleFinish(scope.row)"><i class="el-icon-s-help"></i>工程竣工</el-dropdown-item>
                <el-dropdown-item style="color:gray;" v-if="scope.row.status==1" @click.native="handleNullify(scope.row)"><i class="el-icon-delete"></i>工程作废</el-dropdown-item>
                <el-dropdown-item style="color:blue;" v-if="scope.row.status==3||scope.row.status==4" @click.native="handleRestart(scope.row)"><i class="el-icon-refresh"></i>重回施工</el-dropdown-item>
                <el-dropdown-item style="color:red;" v-if="scope.row.status!=1" @click.native="handleInit(scope.row)"><i class="el-icon-timer"></i>回到未动工</el-dropdown-item>
                <el-dropdown-item style="color:red;" v-if="scope.row.status==4" @click.native="handleDelete(scope.row)"><i class="el-icon-delete-solid"></i>工程删除</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </template>
        </el-table-column>
      </el-table>
      
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </el-card>
    <!-- 详情 -->
    <el-dialog :title="vTitle" :visible.sync="vOpen" width="70%" append-to-body>
      <el-card style="margin-top:-30px">
        <div slot="header" class="clearfix">
          <center><span style="font-weight:bold;font-size:18px;">{{ engineerDetail.name }}</span></center>
        </div>
        <el-descriptions :column="2" border>
          <el-descriptions-item label="工程编码" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            {{ engineerDetail.engineerNo }}
          </el-descriptions-item>
          <el-descriptions-item label="工程代码" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            {{ engineerDetail.code }}
          </el-descriptions-item>
          <el-descriptions-item label="施工单位" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            {{ engineerDetail.ownerDept }}
          </el-descriptions-item>
          <el-descriptions-item label="监理单位" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            {{ engineerDetail.supervisor }}
          </el-descriptions-item>
          <el-descriptions-item label="启动日期" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            {{ engineerDetail.startTime }}
          </el-descriptions-item>
          <el-descriptions-item label="竣工日期" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            {{ engineerDetail.endTime }}
          </el-descriptions-item>
          <el-descriptions-item label="负责人" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            {{ engineerDetail.chargerName }}
          </el-descriptions-item>
          <el-descriptions-item label="负责部门" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            {{ engineerDetail.deptName }}
          </el-descriptions-item>
          <el-descriptions-item label="施工联系人" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            {{ engineerDetail.contactPerson }}
          </el-descriptions-item>
          <el-descriptions-item label="联系方式" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            {{ engineerDetail.contactPhone }}
          </el-descriptions-item>
          <el-descriptions-item label="施工地点" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            {{ engineerDetail.constructSite }}
          </el-descriptions-item>
          <el-descriptions-item label="工程状态" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            <dict-tag :options="dict.type.sys_engineer_status" :value="engineerDetail.status"/>
          </el-descriptions-item>
          <el-descriptions-item label="工程金额" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            {{ engineerDetail.costConstruction | moneyFormat }} <span style="margin-left:10px;">万元</span>
          </el-descriptions-item>
          <el-descriptions-item label="所属项目" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            {{ engineerDetail.projectName }}
          </el-descriptions-item>
          <el-descriptions-item label="创建人" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            {{ engineerDetail.creator }}
          </el-descriptions-item>
          <el-descriptions-item label="创建时间" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            <span>{{ parseTime(engineerDetail.createTime, '{y}-{m}-{d}') }}</span>
          </el-descriptions-item>
        </el-descriptions>
        <el-descriptions :column="1" border style="margin-top:-2px;">
          <el-descriptions-item label="工程描述" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'90%',color: '#329dff' }">
            {{ engineerDetail.describe }}
          </el-descriptions-item>
          <el-descriptions-item label="补充说明" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'90%',color: '#329dff' }">
            {{ engineerDetail.remark }}
          </el-descriptions-item>
        </el-descriptions>
      </el-card>
      <el-card style="margin-top:10px;">
        <div slot="header" class="clearfix">
          <span style="font-weight:bold;color:#1890FF;">工程图片</span>
        </div>
        <new-preview v-if="engineerDetail.contractAttach!=null" :src="engineerDetail.contractAttach" :width="200" :height="200" />
      </el-card>

      <el-card style="margin-top:10px;">
        <div slot="header" class="clearfix">
          <span style="font-weight:bold;color:#1890FF;">工程附件</span>
        </div>
        <file-upload-show :fileList_show="fileList_show" />
      </el-card>

      <el-card style="margin-top:10px;">
        <div slot="header" class="clearfix">
          <span style="font-weight:bold;color:#1890FF;">项目信息</span>
        </div>
        <el-descriptions v-if="projectDetail!=null" :column="2" border>
          <el-descriptions-item label="项目名称" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            {{ projectDetail.name }}
          </el-descriptions-item>
          <el-descriptions-item label="项目代码" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            {{ projectDetail.code }}
          </el-descriptions-item>
          <el-descriptions-item label="施工单位" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            {{ projectDetail.constructDept }}
          </el-descriptions-item>
          <el-descriptions-item label="监理单位" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            {{ projectDetail.supervisor }}
          </el-descriptions-item>
          <el-descriptions-item label="启动日期" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            {{ projectDetail.startTime }}
          </el-descriptions-item>
          <el-descriptions-item label="竣工日期" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            {{ projectDetail.endTime }}
          </el-descriptions-item>
          <el-descriptions-item label="负责人" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            {{ projectDetail.chargerName }}
          </el-descriptions-item>
          <el-descriptions-item label="负责部门" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            {{ projectDetail.deptName }}
          </el-descriptions-item>
          <el-descriptions-item label="施工联系人" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            {{ projectDetail.contactPerson }}
          </el-descriptions-item>
          <el-descriptions-item label="联系方式" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            {{ projectDetail.contactPhone }}
          </el-descriptions-item>
          <el-descriptions-item label="施工地点" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            {{ projectDetail.constructSite }}
          </el-descriptions-item>
          <el-descriptions-item label="项目状态" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            <dict-tag :options="dict.type.sys_project_status" :value="projectDetail.status"/>
          </el-descriptions-item>
          <el-descriptions-item label="创建人" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            {{ projectDetail.creator }}
          </el-descriptions-item>
          <el-descriptions-item label="创建时间" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'40%',color: '#329dff' }">
            <span>{{ parseTime(projectDetail.createTime, '{y}-{m}-{d}') }}</span>
          </el-descriptions-item>
        </el-descriptions>
        <el-descriptions v-if="projectDetail!=null" :column="1" border style="margin-top:-2px;">
          <el-descriptions-item label="项目金额" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'90%',color: '#329dff' }">
            {{ projectDetail.totalInvest | moneyFormat }} <span style="margin-left:10px;">万元</span>
          </el-descriptions-item>
          <el-descriptions-item label="项目描述" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'90%',color: '#329dff' }">
            {{ projectDetail.describe }}
          </el-descriptions-item>
          <el-descriptions-item label="补充说明" :labelStyle="{width:'10%','text-align': 'center'}" :contentStyle="{ width:'90%',color: '#329dff' }">
            {{ projectDetail.remark }}
          </el-descriptions-item>
        </el-descriptions>
        <span v-if="projectDetail==null" style="color:red;">暂未挂接项目</span>
      </el-card>

      <el-card style="margin-top:10px;">
        <div slot="header" class="clearfix">
          <span style="font-weight:bold;color:#1890FF;">子工程信息</span>
        </div>
        <el-table v-if="subEngineerList4Detail.length>0" :data="subEngineerList4Detail" border>
          <el-table-column label="序号" align="center"  type="index" width="55"/>
          <el-table-column label="名称" align="center" prop="name" />
          <el-table-column label="代码" align="center" prop="code" />
          <el-table-column label="类型" align="center" prop="engineerTypeName">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.sys_sub_engineer_type" :value="scope.row.engineerType"/>
            </template>
          </el-table-column>
          <el-table-column label="所属工程" align="center" prop="engineerName" />
          <el-table-column label="所属项目" align="center" prop="projectName" />
          <el-table-column label="金额(万元)" align="center" prop="costConstruction">
            <template slot-scope="scope">
              <span style="color:blue;">{{ scope.row.costConstruction | moneyFormat }}</span>
            </template>
          </el-table-column>
          <el-table-column label="施工单位" align="center" prop="ownerDept" />
          <el-table-column label="监理单位" align="center" prop="supervisor" />
          <el-table-column label="状态" align="center" prop="status">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.sys_sub_engineer_status" v-if="scope.row.status==1" style="color:red;" :value="scope.row.status"/>
              <dict-tag :options="dict.type.sys_sub_engineer_status" v-if="scope.row.status==2" style="color:blue;" :value="scope.row.status"/>
              <dict-tag :options="dict.type.sys_sub_engineer_status" v-if="scope.row.status==3" style="color:green;" :value="scope.row.status"/>
              <dict-tag :options="dict.type.sys_sub_engineer_status" v-if="scope.row.status==4" style="color:gray;" :value="scope.row.status"/>
            </template>
          </el-table-column>
        </el-table>
        <span v-if="subEngineerList4Detail.length==0" style="color:red;">暂未挂接子工程</span>
      </el-card>

      <el-card style="margin-top:10px;">
        <div slot="header" class="clearfix">
          <span style="font-weight:bold;color:#1890FF;">工程数据集</span>
        </div>
        <el-table :data="engineerDatasetsList" border>
          <el-table-column label="序号" align="center" type="index" />
          <el-table-column label="名称" align="center" prop="name" />
          <el-table-column label="编码" align="center" prop="code" />
          <el-table-column label="类型" align="center" prop="type" width="120">
          <template slot-scope="scope">
              <dict-tag :options="dict.type.sy_dataset_type" :value="scope.row.type"/>
          </template>
          </el-table-column>
          <el-table-column label="状态" align="center" prop="status" width="120">
          <template slot-scope="scope">
              <dict-tag :options="dict.type.sy_dataset_status" v-if="scope.row.status==0" style="color:blue" :value="scope.row.status"/>
              <dict-tag :options="dict.type.sy_dataset_status" v-if="scope.row.status==1" style="color:green" :value="scope.row.status"/>
              <dict-tag :options="dict.type.sy_dataset_status" v-if="scope.row.status==2" style="color:red" :value="scope.row.status"/>
          </template>
          </el-table-column>
          <el-table-column label="创建人" align="center" prop="creator" width="120" />
          <el-table-column label="创建日期" align="center" prop="createTime" width="120">
          <template slot-scope="scope">
              <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
          </template>
          </el-table-column>
          <el-table-column label="发布人员" align="center" prop="publisher" width="120" />
          <el-table-column label="发布日期" align="center" prop="publishTime" width="120">
          <template slot-scope="scope">
              <span>{{ parseTime(scope.row.publishTime, '{y}-{m}-{d}') }}</span>
          </template>
          </el-table-column>
        </el-table>
      </el-card>

      <el-card style="margin-top:10px;">
        <div slot="header" class="clearfix">
          <span style="font-weight:bold;color:#1890FF;">工程待办事项</span>
        </div>
        <el-table :data="itemsList" border>
          <el-table-column label="序号" align="center" type="index" />
          <el-table-column label="事项标题" align="left" prop="itemName" />
          <el-table-column label="发起人" align="center" prop="createName" width="100" />
          <el-table-column label="发起日期" align="center" prop="createTime" width="120">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
            </template>
          </el-table-column>
          <el-table-column label="当前跟进人" align="center" prop="followupName" width="120">
            <template slot-scope="scope">
              <span v-if="scope.row.status==2">-</span>
              <span v-if="scope.row.status!=2">{{scope.row.followupName}}</span>
            </template>
          </el-table-column>
          <el-table-column label="跟进状态" align="center" prop="status" width="100">
            <template slot-scope="scope">
              <span v-if="scope.row.status==0" style="color:blue;">待跟进</span>
              <span v-if="scope.row.status==1" style="color:red;">跟进中</span>
              <span v-if="scope.row.status==2" style="color:green;">已结束</span>
            </template>
          </el-table-column>
          <el-table-column label="截止日期" align="center" prop="deadTime" width="120" />
        </el-table>
      </el-card>

      <div slot="footer" class="dialog-footer" v-if="startEngineer==true||finishEngineer==true||nullifyEngineer==true||deleteEngineer==true||restartEngineer==true||initEngineer==true">
        <el-button type="success" v-show="startEngineer" @click="processStartEngineer(engineerDetail)">工程启动</el-button>
        <el-button type="warning" v-show="finishEngineer" @click="processFinishEngineer(engineerDetail)">工程竣工</el-button>
        <el-button type="info" v-show="nullifyEngineer" @click="processNullifyEngineer(engineerDetail)">工程作废</el-button>
        <el-button type="primary" v-show="restartEngineer" @click="processRestartEngineer(engineerDetail)">重回施工</el-button>
        <el-button type="danger" v-show="initEngineer" @click="processInitEngineer(engineerDetail)">回到未动工</el-button>
        <el-button type="danger" v-show="deleteEngineer" @click="processDeleteEngineer(engineerDetail)">工程删除</el-button>
      </div>
    </el-dialog>
    <!-- 修改 -->
    <el-dialog :title="title" :visible.sync="open" width="70%" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-card style="margin-top:-2px;">
          <div slot="header" class="clearfix">
            <span style="color:#329dff;font-weight:bold;font-size:14px;">工程信息</span>
          </div>

          <el-row>
              <el-col :span="12">
                <el-form-item label="工程编码" prop="engineerNo">
                  <el-input v-model="form.engineerNo" disabled />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="工程代码" prop="code">
                  <el-input v-model="form.code" />
                </el-form-item>
              </el-col>
          </el-row>

          <el-row>
              <el-col :span="12">
                <el-form-item label="工程名称" prop="name">
                  <el-input v-model="form.name" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="工程金额" prop="costConstruction">
                  <el-input-number style="width:95%;color:red;" v-model="form.costConstruction" :controls="false" :precision="4" /><span style="color:blue;margin-left:5px;">万元</span>
                </el-form-item>
              </el-col>
          </el-row>

          <el-row>
            <el-col :span="24">
              <el-form-item label="所属项目" prop="projectId">
                <el-select v-model="form.projectId" filterable clearable placeholder="请选择所属项目" style="width:100%;">
                  <el-option v-for="item in projectList" :key="item.uuid" :label="item.name" :value="item.uuid"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="12">
              <el-form-item label="启动日期" prop="startTime">
                <el-date-picker clearable size="small" style="width:100%;" v-model="form.startTime" type="date" value-format="yyyy-MM-dd" placeholder="选择启动日期"></el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="竣工日期" prop="endTime">
                <el-date-picker clearable size="small" style="width:100%;" v-model="form.endTime" type="date" value-format="yyyy-MM-dd" placeholder="选择竣工日期"></el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="12">
              <el-form-item label="负责人" prop="chargerId">
                <el-select v-model="form.chargerId" filterable placeholder="请选择负责人" style="width:100%;">
                  <el-option v-for="item in participants" :key="item.userId" :label="item.nickName" :value="item.userId"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="负责部门" prop="deptId">
                <treeselect v-model="form.deptId" :options="deptOptions" :show-count="true" placeholder="请选择负责部门" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="12">
            <el-form-item label="施工单位" prop="ownerDept">
              <el-input v-model="form.ownerDept" />
            </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="监理单位" prop="supervisor">
                <el-input v-model="form.supervisor" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="12">
            <el-form-item label="施工联系人" prop="contactPerson">
              <el-input v-model="form.contactPerson" />
            </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="联系方式" prop="contactPhone">
                <el-input v-model="form.contactPhone" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="24">
              <el-form-item label="施工地点" prop="constructSite">
                <el-input v-model="form.constructSite" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="24">
              <el-form-item label="工程描述" prop="describe">
                <el-input type="textarea" v-model="form.describe" :rows="6"></el-input>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="24">
              <el-form-item label="补充说明" prop="remark">
                <el-input type="textarea" v-model="form.remark" :rows="6"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-card>

        <el-card style="margin-top:10px;">
          <div slot="header" class="clearfix">
            <span style="color:#329dff;font-weight:bold;font-size:14px;">挂接子工程</span>
          </div>
          <el-table ref="table" :data="subEngineerList" @selection-change="handleSelectionChange" border :row-key="getRowKeys" style="margin-top:10px;">
            <el-table-column type="selection" width="50" align="center" :selectable="selectable" />
            <el-table-column label="名称" align="center" prop="name" />
            <el-table-column label="代码" align="center" prop="code" />
            <el-table-column label="类型" align="center" prop="engineerTypeName">
              <template slot-scope="scope">
                <dict-tag :options="dict.type.sys_sub_engineer_type" :value="scope.row.engineerType"/>
              </template>
            </el-table-column>
            <el-table-column label="所属工程" align="center" prop="engineerName" />
            <el-table-column label="所属项目" align="center" prop="projectName" />
            <el-table-column label="金额(万元)" align="center" prop="costConstruction">
              <template slot-scope="scope">
                <span style="color:blue;">{{ scope.row.costConstruction | moneyFormat }}</span>
              </template>
            </el-table-column>
            <el-table-column label="施工单位" align="center" prop="ownerDept" />
            <el-table-column label="监理单位" align="center" prop="supervisor" />
            <el-table-column label="状态" align="center" prop="status">
              <template slot-scope="scope">
                <dict-tag :options="dict.type.sys_sub_engineer_status" v-if="scope.row.status==1" style="color:red;" :value="scope.row.status"/>
                <dict-tag :options="dict.type.sys_sub_engineer_status" v-if="scope.row.status==2" style="color:blue;" :value="scope.row.status"/>
                <dict-tag :options="dict.type.sys_sub_engineer_status" v-if="scope.row.status==3" style="color:green;" :value="scope.row.status"/>
                <dict-tag :options="dict.type.sys_sub_engineer_status" v-if="scope.row.status==4" style="color:gray;" :value="scope.row.status"/>
              </template>
            </el-table-column>
            <el-table-column label="操作" align="center" width="100">
              <template slot-scope="scope">
                <el-button v-if="scope.row.hasEngineer==1" type="text" @click="unhookSubEngineer(scope.row)">解除挂接</el-button>
              </template>
            </el-table-column>
          </el-table>
        </el-card>

        <el-card style="margin-top:10px;">
          <div slot="header" class="clearfix">
            <span style="color:#329dff;font-weight:bold;font-size:14px;">工程附件</span>
          </div>
          <el-row>
              <el-col :span="24">
                <el-form-item prop="contractAttach">
                  <image-upload-custom v-model="form.contractAttach" :limit="10000" :imageName="imageName"></image-upload-custom>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="24">
                <el-form-item prop="materialAttach">
                  <file-upload-custom
                    :fileSize="10000"
                    :attachName="attachOtherName"
                    :fileList_show="fileList_show"
                    v-model="form.materialAttach"
                    @addlist="fileList_show_add"
                    @deletlist="fileList_show_delet"
                  />
                </el-form-item>
              </el-col>
            </el-row>
        </el-card>
    </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import { listEngineer,getEngineer,editEngineer,processStartEngineer,processFinishEngineer,processNullifyEngineer,processRestartEngineer,processDeleteEngineer,processInitEngineer } from "@/api/system/engineer";
import { treeselect } from "@/api/system/dept";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import { listAllUser } from "@/api/system/user";
import { getProjectList,getProject } from "@/api/system/project";
import { getSubEngineerList4Engineer,unhookSubEngineer,getSubEngineer4ProjectDetail } from "@/api/system/subengineer";
import { getBindEngineerDatasets } from "@/api/system/dataset";
import { getItemListByItemParentId } from "@/api/system/items";

export default {
  name: "QueryEngineer",
  dicts: ['sys_engineer_status','sys_project_status','sys_sub_engineer_status','sys_sub_engineer_type','sy_dataset_status','sy_dataset_type'],
  components:{ Treeselect },
  data() {
    return {
      itemsList: [],
      attachPdfName: '上传PDF',
      attachOtherName: '上传文件',
      imageName: '上传图片',
      participants: [],
      deptOptions: [],
      fileList_show:[],
      projectList: [],
      moneyFormat: 4,
      engineerDetail: {},
      startEngineer: false,
      finishEngineer: false,
      nullifyEngineer: false,
      deleteEngineer: false,
      restartEngineer: false,
      initEngineer: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 工程信息表表格数据
      engineerList: [],
      projectDetail: {},
      subEngineerList: [],
      subEngineerList4Detail: [],
      engineerDatasetsList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      vOpen: false,
      // 弹出层标题
      vTitle: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        code: null,
        startTime: null,
        endTime: null,
        status: null,
        costConstruction: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        EngineerNo: [
          { required: true, message: "工程编号不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
    this.listAllUser();
    this.getTreeselect();
    this.getProjectList();
  },
  methods: {
    unhookSubEngineer(row){
      let engineerId = row.engineerId;
      unhookSubEngineer(row).then(res => {
        if(res.code==200){
          this.getSubEngineerList4Engineer(engineerId)
        }
      })
    },
    getSubEngineerList4Engineer(engineerId){
      let query = {
        engineerId: engineerId
      };
      getSubEngineerList4Engineer(query).then(res =>{
        this.subEngineerList = res.data;
        var that = this;
        that.$nextTick(() => {
          this.subEngineerList.forEach((v, i) => {
            if (v.hasEngineer == 1) {
              this.$refs.table.toggleRowSelection(v, true);
            }
          });
        });
      })
    },
    getProjectList(){
      getProjectList().then(res =>{
        this.projectList = res.data;
      })
    },
    /** 查询工程信息表列表 */
    getList() {
      this.loading = true;
      listEngineer(this.queryParams).then(response => {
        this.engineerList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        uuid: null,
        projectNo: null,
        name: null,
        code: null,
        startTime: null,
        endTime: null,
        describe: null,
        status: null,
        chargerId: null,
        deptId: null,
        contactPerson: null,
        contactPhone: null,
        totalInvest: null,
        constructDept: null,
        constructSite: null,
        supervisor: null,
        contractAttach: null,
        materialAttach: null,
        roleIds: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        subEngineerIds: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    getRowKeys(row) {
      return row.uuid;
    },
    selectable(row, index) {
      if (row.hasEngineer == 1) {
        return false; // 禁用
      } else {
        return true; //不禁用
      }
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.uuid)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加工程信息";
    },
    handleView(row){
      this.fileList_show = [];
      this.engineerDetail = {};
      getEngineer(row.uuid).then(res => {
        this.engineerDetail = res.data;
        this.vOpen = true;
        this.vTitle = "工程详情";
        this.fileList_show = res.data.attachList;
        this.startEngineer = false;
        this.finishEngineer = false;
        this.nullifyEngineer = false;
        this.deleteEngineer = false;
        this.restartEngineer = false;
        this.initEngineer = false;
        this.projectDetail = null;
        if(row.projectId!=null){
          getProject(row.projectId).then(res => {
            this.projectDetail = res.data;
          });
        }
        getSubEngineer4ProjectDetail({engineerId:row.uuid}).then(res =>{
          this.subEngineerList4Detail = res.data;
        })
        //获取数据集
        let query = {
          engineerIds: row.uuid
        }
        getBindEngineerDatasets(query).then(res =>{
          this.engineerDatasetsList = [];
          this.engineerDatasetsList = res.data;
        })
        // 获取待办事项
        let itemQuery = {
          itemParentId:row.uuid
        }
        getItemListByItemParentId(itemQuery).then(res =>{
          this.itemsList = [];
          this.itemsList = res.data;
        })
      });
    },
    handleInit(row){
      this.fileList_show = [];
      this.engineerDetail = {};
      getEngineer(row.uuid).then(res => {
        this.engineerDetail = res.data;
        this.vOpen = true;
        this.vTitle = "工程详情";
        this.fileList_show = res.data.attachList;
        this.startEngineer = false;
        this.finishEngineer = false;
        this.nullifyEngineer = false;
        this.deleteEngineer = false;
        this.restartEngineer = false;
        this.initEngineer = true;

        if(row.projectId!=null){
          getProject(row.projectId).then(res => {
            this.projectDetail = res.data;
          });
        }
        getSubEngineer4ProjectDetail({engineerId:row.uuid}).then(res =>{
          this.subEngineerList4Detail = res.data;
        })
        //获取数据集
        let query = {
          engineerIds: row.uuid
        }
        getBindEngineerDatasets(query).then(res =>{
          this.engineerDatasetsList = [];
          this.engineerDatasetsList = res.data;
        })
        // 获取待办事项
        let itemQuery = {
          itemParentId:row.uuid
        }
        getItemListByItemParentId(itemQuery).then(res =>{
          this.itemsList = [];
          this.itemsList = res.data;
        })
      });
    },
    handleRestart(row){
      this.fileList_show = [];
      this.engineerDetail = {};
      getEngineer(row.uuid).then(res => {
        this.engineerDetail = res.data;
        this.vOpen = true;
        this.vTitle = "工程详情";
        this.fileList_show = res.data.attachList;
        this.startEngineer = false;
        this.finishEngineer = false;
        this.nullifyEngineer = false;
        this.deleteEngineer = false;
        this.restartEngineer = true;
        this.initEngineer = false;
        if(row.projectId!=null){
          getProject(row.projectId).then(res => {
            this.projectDetail = res.data;
          });
        }
        getSubEngineer4ProjectDetail({engineerId:row.uuid}).then(res =>{
          this.subEngineerList4Detail = res.data;
        })
        //获取数据集
        let query = {
          engineerIds: row.uuid
        }
        getBindEngineerDatasets(query).then(res =>{
          this.engineerDatasetsList = [];
          this.engineerDatasetsList = res.data;
        })
        // 获取待办事项
        let itemQuery = {
          itemParentId:row.uuid
        }
        getItemListByItemParentId(itemQuery).then(res =>{
          this.itemsList = [];
          this.itemsList = res.data;
        })
      });
    },
    handleStart(row){
      this.fileList_show = [];
      this.engineerDetail = {};
      getEngineer(row.uuid).then(res => {
        this.engineerDetail = res.data;
        this.vOpen = true;
        this.vTitle = "工程详情";
        this.fileList_show = res.data.attachList;
        this.startEngineer = true;
        this.finishEngineer = false;
        this.nullifyEngineer = false;
        this.deleteEngineer = false;
        this.restartEngineer = false;
        this.initEngineer = false;
        if(row.projectId!=null){
          getProject(row.projectId).then(res => {
            this.projectDetail = res.data;
          });
        }
        getSubEngineer4ProjectDetail({engineerId:row.uuid}).then(res =>{
          this.subEngineerList4Detail = res.data;
        })
        //获取数据集
        let query = {
          engineerIds: row.uuid
        }
        getBindEngineerDatasets(query).then(res =>{
          this.engineerDatasetsList = [];
          this.engineerDatasetsList = res.data;
        })
        // 获取待办事项
        let itemQuery = {
          itemParentId:row.uuid
        }
        getItemListByItemParentId(itemQuery).then(res =>{
          this.itemsList = [];
          this.itemsList = res.data;
        })
      });
    },
    handleFinish(row){
      this.fileList_show = [];
      this.engineerDetail = {};
      getEngineer(row.uuid).then(res => {
        this.engineerDetail = res.data;
        this.vOpen = true;
        this.vTitle = "工程详情";
        this.fileList_show = res.data.attachList;
        this.startEngineer = false;
        this.finishEngineer = true;
        this.nullifyEngineer = false;
        this.deleteEngineer = false;
        this.restartEngineer = false;
        this.initEngineer = false;
        if(row.projectId!=null){
          getProject(row.projectId).then(res => {
            this.projectDetail = res.data;
          });
        }
        getSubEngineer4ProjectDetail({engineerId:row.uuid}).then(res =>{
          this.subEngineerList4Detail = res.data;
        })
        //获取数据集
        let query = {
          engineerIds: row.uuid
        }
        getBindEngineerDatasets(query).then(res =>{
          this.engineerDatasetsList = [];
          this.engineerDatasetsList = res.data;
        })
        // 获取待办事项
        let itemQuery = {
          itemParentId:row.uuid
        }
        getItemListByItemParentId(itemQuery).then(res =>{
          this.itemsList = [];
          this.itemsList = res.data;
        })
      });
    },
    handleNullify(row){
      this.fileList_show = [];
      this.engineerDetail = {};
      getEngineer(row.uuid).then(res => {
        this.engineerDetail = res.data;
        this.vOpen = true;
        this.vTitle = "工程详情";
        this.fileList_show = res.data.attachList;
        this.startEngineer = false;
        this.finishEngineer = false;
        this.nullifyEngineer = true;
        this.deleteEngineer = false;
        this.restartEngineer = false;
        this.initEngineer = false;
        if(row.projectId!=null){
          getProject(row.projectId).then(res => {
            this.projectDetail = res.data;
          });
        }
        getSubEngineer4ProjectDetail({engineerId:row.uuid}).then(res =>{
          this.subEngineerList4Detail = res.data;
        })
        //获取数据集
        let query = {
          engineerIds: row.uuid
        }
        getBindEngineerDatasets(query).then(res =>{
          this.engineerDatasetsList = [];
          this.engineerDatasetsList = res.data;
        })
        // 获取待办事项
        let itemQuery = {
          itemParentId:row.uuid
        }
        getItemListByItemParentId(itemQuery).then(res =>{
          this.itemsList = [];
          this.itemsList = res.data;
        })
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      this.fileList_show = [];
      this.engineerDetail = {};
      getEngineer(row.uuid).then(res => {
        this.engineerDetail = res.data;
        this.vOpen = true;
        this.vTitle = "工程详情";
        this.fileList_show = res.data.attachList;
        this.startEngineer = false;
        this.finishEngineer = false;
        this.nullifyEngineer = false;
        this.deleteEngineer = true;
        this.restartEngineer = false;
        this.initEngineer = false;
        if(row.projectId!=null){
          getProject(row.projectId).then(res => {
            this.projectDetail = res.data;
          });
        }
        getSubEngineer4ProjectDetail({engineerId:row.uuid}).then(res =>{
          this.subEngineerList4Detail = res.data;
        })
        //获取数据集
        let query = {
          engineerIds: row.uuid
        }
        getBindEngineerDatasets(query).then(res =>{
          this.engineerDatasetsList = [];
          this.engineerDatasetsList = res.data;
        })
        // 获取待办事项
        let itemQuery = {
          itemParentId:row.uuid
        }
        getItemListByItemParentId(itemQuery).then(res =>{
          this.itemsList = [];
          this.itemsList = res.data;
        })
      });
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.fileList_show = [];
      getEngineer(row.uuid).then(res => {
        this.form = res.data;
        this.open = true;
        this.title = "修改工程信息";
        this.fileList_show = res.data.attachList;

        // 获取子工程
        let query = {
          engineerId: row.uuid
        };
        getSubEngineerList4Engineer(query).then(res =>{
          this.subEngineerList = res.data;
          var that = this;
          that.$nextTick(() => {
            this.subEngineerList.forEach((v, i) => {
              if (v.hasEngineer == 1) {
                this.$refs.table.toggleRowSelection(v, true);
              }
            });
          });
        })
      });
    },
    listAllUser(){
      listAllUser().then(res =>{
        this.participants = res.data;
      })
    },
    getTreeselect() {
      treeselect().then(response => {
        this.deptOptions = response.data;
      });
    },
    // 文件上传接收子组件值，同步（增）
    fileList_show_add(val){
      this.fileList_show = this.fileList_show.concat(val);
    },
    // 文件上传接收子组件值，同步（减）
    fileList_show_delet(val){
      this.fileList_show.splice(val, 1);
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if(this.ids.length>0){
            this.form.subEngineerIds = this.ids.join(",");
          }
          if (this.form.uuid != null) {
            editEngineer(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            editEngineer(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    processStartEngineer(row){
      this.$modal.confirm('是否确认启动工程 "' + row.name + '" ？').then(function() {
        return processStartEngineer(row);
      }).then(() => {
        this.getList();
        this.vOpen = false;
        this.$modal.msgSuccess("启动成功");
      }).catch(() => {});
    },
    processFinishEngineer(row){
      this.$modal.confirm('是否确认工程 "' + row.name + '" 竣工？').then(function() {
        return processFinishEngineer(row);
      }).then(() => {
        this.getList();
        this.vOpen = false;
        this.$modal.msgSuccess("竣工成功");
      }).catch(() => {});
    },
    processNullifyEngineer(row){
      this.$modal.confirm('是否确认作废工程 "' + row.name + '" ？').then(function() {
        return processNullifyEngineer(row);
      }).then(() => {
        this.getList();
        this.vOpen = false;
        this.$modal.msgSuccess("作废成功");
      }).catch(() => {});
    },
    processRestartEngineer(row){
      this.$modal.confirm('是否确认工程 "' + row.name + '" 重回施工？').then(function() {
        return processRestartEngineer(row);
      }).then(() => {
        this.getList();
        this.vOpen = false;
        this.$modal.msgSuccess("重回施工成功");
      }).catch(() => {});
    },
    processDeleteEngineer(row){
      this.$modal.confirm('是否确认删除工程 "' + row.name + '" ？').then(function() {
        return processDeleteEngineer(row);
      }).then(() => {
        this.getList();
        this.vOpen = false;
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    processInitEngineer(row){
      this.$modal.confirm('是否确认工程 "' + row.name + '" 回到未动工？').then(function() {
        return processInitEngineer(row);
      }).then(() => {
        this.getList();
        this.vOpen = false;
        this.$modal.msgSuccess("回到未动工成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/project/export', {
        ...this.queryParams
      }, `project_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
